package com.support.android.myapp3.bean;

import com.support.android.myapp3.fragment.TaxCardFragment;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class TaxItemBean {

    private String item1;
    private String item2;
    private String item3;
    private String personPer;
    private String companyPer;
    private BigDecimal moneyFen;
    private BigDecimal ONE = new BigDecimal("100");

    public TaxItemBean(String item1,String item2,String item3){
        this.item1 = item1;
        this.item2 = item2;
        this.item3 = item3;
    }

    public TaxItemBean(String name,String personPer,String companyPer,String moneyYuan){
        this.item1 = name;
        this.personPer = personPer;
        this.companyPer = companyPer;
        this.moneyFen = new BigDecimal(moneyYuan).divide(ONE);

        this.item2 = calcMoneyStr(moneyFen,personPer);
        this.item3 = calcMoneyStr(moneyFen,companyPer);
    }

    public BigDecimal calcPersonValYuan(){
        return calcMoney(moneyFen,personPer).multiply(ONE);
    }

    public BigDecimal calcCompayValYuan(){
        return calcMoney(moneyFen,companyPer).multiply(ONE);
    }


    public BigDecimal calcMoney(BigDecimal moneyFen, String per){
        BigDecimal p = new BigDecimal(per);

        p = p.divide(ONE);

        return moneyFen.multiply(p);
    }


    public String calcMoneyStr(BigDecimal money,String per){
        return calcMoney( money, per).multiply(ONE)
                .setScale(2, BigDecimal.ROUND_HALF_DOWN).toString()+String.format("(%s%%)",per);
    }

    public String getItem1() {
        return item1;
    }

    public void setItem1(String item1) {
        this.item1 = item1;
    }

    public String getItem2() {
        return item2;
    }

    public void setItem2(String item2) {
        this.item2 = item2;
    }

    public String getItem3() {
        return item3;
    }

    public void setItem3(String item3) {
        this.item3 = item3;
    }

    public Map<String,String> genItem(){
        HashMap<String, String> item = new HashMap<String, String>();
        item.put("p_name",item1);
        item.put("p_person",item2);
        item.put("p_company",item3);
        return item;
    }

    public float calcPer(){
        return calcPersonValYuan().divide(moneyFen.multiply(ONE)).multiply(ONE).floatValue();
    }

    public String show(){
        return String.format("%s:比例%s%%:%s ",item1,calcPersonValYuan().divide(moneyFen.multiply(ONE)).multiply(ONE).setScale(2, BigDecimal.ROUND_HALF_DOWN).toString(),
                calcPersonValYuan().setScale(2, BigDecimal.ROUND_HALF_DOWN).toString());
    }

}
